/**
 * @file storeUtils.ts
 * @description store工具类
 * @module utils/storeUtils
 * @author kikolove
 */
import { app } from 'electron';
import Store from 'electron-store'
const storeDefaultOptions = {
    name: 'config',
    // encryptionKey: '6b2fa44c518566e81dcd395485a8264d94722d7202ee8a93224cffef8947f5c5',//kikolove
    fileExtension: 'json',
    clearInvalidConfig: true,
}
class StoreUtils {
    static initData() {
        this.setStore('isFirst', 'true');
        this.setStore('apiKey', '');
        // this.setStore('apiOrg', 'org-JRs08jIKuEtpePdwv6Tke7I6');

    }
    static getStore(name: string, option?: any) {
        const opt = option ?? storeDefaultOptions
        const store = new Store(opt);
        return store.get(name);
    }
    static setStore(name: string, value: string, option?: any) {
        const opt = option ?? storeDefaultOptions
        const store = new Store(opt);
        if (value === null) {
            store.delete(name);
        } else {
            store.set(name, value);
        }
    }
    static removeStore(name: string, option?: any) {
        const opt = option ?? storeDefaultOptions
        const store = new Store(opt);
        store.delete(name);
    }
    static clearStore(option?: any) {
        const opt = option ?? storeDefaultOptions
        const store = new Store(opt);
        store.clear();
    }
    static hasStore(name: string, option?: any) {
        const opt = option ?? storeDefaultOptions
        const store = new Store(opt);
        //首先检查本地是否存在配置文件，再检查是否存在对应的配置项,如果不存在配置文件，直接返回false
        if (store.path) {
            return store.has(name);
        } else {
            return false;
        }

    }
    static getAppPath() {
        return app.getPath('userData');
    }

}

export default StoreUtils;
